/**
 * JE Career package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

function display(asas)
{
	if(asas==1){
		document.getElementById('resume').style.display = 'block';
		document.getElementById('resume_span').style.display = 'block';
		document.getElementById('text_resume').style.display = 'none';
	}
	if(asas==2){
		document.getElementById('text_resume').style.display = 'block';
		document.getElementById('resume').style.display ='none';
		document.getElementById('resume_span').style.display = 'none';
	}
}

function clickpaste()
{
	if(document.getElementById('text_resume').value == 'Paste here'){
		document.getElementById('text_resume').value = '';
	}
}
function clickpaste1()
{
	if(document.getElementById('text_resume').value == ''){
		document.getElementById('text_resume').value = 'Paste here';
	}
	clearLabel('resume');
}

function submitbutton(pressbutton)
{
	var condition  	= pressbutton;
	var fullname 	= document.getElementById('fullname').value;
	var email_c_o	= document.getElementById('email_c_o').value;
	//var mobile		= document.getElementById('mobile').value;
	var resume		= document.getElementById('resume').value;
	var text_resume	= document.getElementById('text_resume').value;
	var capcha_y_n	= document.getElementById('capcha_y_n').value;

	document.getElementById('fullname-error').style.color	= '#666666';
	document.getElementById('email_c_o-error').style.color 	= '#666666';
	//document.getElementById('mobile-error').style.color 	= '#666666';
	document.getElementById('resume-error').style.color 	= '#666666';
	document.getElementById('error').innerHTML 				= '';

	var tables       		= document.getElementsByTagName('input');
	var toggletables 		= [];
	var ii=1;
	var focus=0;
	for (i in tables) {
		if (tables[i].id) {
			var selrequwh  	= tables[i].className.split(" ");
			var requ  		= selrequwh[0];
    		var value 		= document.getElementById(tables[i].id).value;

			// Required Field...
			if(requ == 'required') {
				if (trim(value) == '') {
					focus++;
					var inputerror 												= document.getElementById(tables[i].id+'_l-error');
					inputerror.style.color 										= '#FF0000';
					if(focus==1)
					document.getElementById(tables[i].id).focus();
					ii															=2;
				}
			}
		}
	}
	if(ii==2){
		if (trim(resume) == '' && text_resume == 'Paste here'){
		document.getElementById('resume-error').style.color 					= '#FF0000';
		document.getElementById('resume_l-error').style.color 					= '#FF0000';

		}
		return false;
	}
	if(capcha_y_n=='yes'){
		var captcha= document.getElementById('autarticaptcha_entry').value;
		document.getElementById('autarticaptcha_entry-error').style.color 		= '#666666';
	}
	if (trim(fullname) == ''){
		document.getElementById('fullname-error').innerHTML 					= 'Please Enter your full name';
		document.getElementById('fullname-error').style.color 					= '#FF0000';
		document.getElementById('fullname_l-error').style.color 				= '#FF0000';
		document.getElementById('fullname').focus();
		return false;
	}
	if (trim(fullname) != ''){
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		for (var i = 0; i < fullname.length; i++){
	   		if (iChars.indexOf(fullname.charAt(i)) != -1){
    			document.getElementById('fullname-error').innerHTML 			= 'Please remove the special characters';
    			document.getElementById('fullname-error').style.color 			= '#FF0000';
				document.getElementById('fullname_l-error').style.color 		= '#FF0000';
				document.getElementById('fullname').focus();
				return false;
        	}
        }
	}
	if (trim(fullname) != ''){
		var iChars 																= "0123456789";
		for (var i = 0; i < fullname.length; i++){
	   		if (iChars.indexOf(fullname.charAt(i)) != -1){
				document.getElementById('fullname-error').innerHTML 			= 'Please remove numbers';
				document.getElementById('fullname-error').style.color 			= '#FF0000';
				document.getElementById('fullname_l-error').style.color 		= '#FF0000';
				document.getElementById('fullname').focus();
				return false;
        	}
        }
	}
	if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_c_o) == false)){
		document.getElementById('email_c_o-error').innerHTML 					= 'Please Enter valid e-mail';
		document.getElementById('email_c_o-error').style.color 					= '#FF0000';
		document.getElementById('email_c_o_l-error').style.color 				= '#FF0000';
		document.getElementById('email_c_o').focus();
		return false;
	}
//	if (trim(mobile) == ''){
//		document.getElementById('mobile-error').innerHTML 						= 'Please Enter mobile number';
//		document.getElementById('mobile-error').style.color 					= '#FF0000';
//		document.getElementById('mobile_l-error').style.color 					= '#FF0000';
//		document.getElementById('mobile').focus();
//		return false;
//	}
//	if (!/\D/.test(mobile) == false){
//		document.getElementById('mobile-error').innerHTML 						= 'Please Enter valid mobile number';
//		document.getElementById('mobile-error').style.color 					= '#FF0000';
//		document.getElementById('mobile_l-error').style.color 					= '#FF0000';
//		document.getElementById('mobile').focus();
//		return false;
//	}
	if (trim(resume) == '' && text_resume == 'Paste here'){
		document.getElementById('resume-error').innerHTML 						= 'Please upload/paste file';
		document.getElementById('resume-error').style.color 					= '#FF0000';
		document.getElementById('resume_l-error').style.color 					= '#FF0000';
		return false;
	}
	if(capcha_y_n=='yes'){
		if (trim(captcha) == ''){
			document.getElementById('error').innerHTML 							= 'Please Enter captcha sequence';
			document.getElementById('autarticaptcha_entry_l-error').style.color = '#FF0000';
			document.getElementById('autarticaptcha_entry').focus();
			return false;
		}
	}
	return true;
}

function ltrim(str) {
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars 														= " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function clearLabel(id)
{
	if(document.getElementById(id).value != '') {
		document.getElementById('error').innerHTML 								= '';
		document.getElementById(id+'_l-error').style.color	 					= '#666666';
		document.getElementById(id+'-error').innerHTML	 						= '';
	}
	if(id=='resume'){
		if (document.getElementById('text_resume').value != 'Paste here'){
			document.getElementById('error').innerHTML 							= '';
			document.getElementById(id+'_l-error').style.color 					= '#666666';
			document.getElementById(id+'-error').innerHTML 						= '';
		}
	}
}
